package com.example.cpms.controller;

import com.example.cpms.entity.Building;
import com.example.cpms.entity.RodManage;
import com.example.cpms.service.RodManageService;
import com.example.cpms.utils.PageBean;
import com.example.cpms.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Slf4j
@RestController
public class RodManageControl {

    @Autowired
    private RodManageService rodManageService;

    /**
     * 一体杆的分页查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/pole/info")  //改用PageHelper插件
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10")Integer pageSize,
                       String poleName,String poleNumber, Integer poleStatus){
        log.info("一体杆分页查询：{}，{},{}",page,pageSize,poleName,poleNumber,poleStatus);
        PageBean pageBean = rodManageService.page(page,pageSize,poleName,poleNumber,poleStatus);
        return Result.success(pageBean);
    }

    /**
     *根据id删除
     * @return
     */
    @DeleteMapping("/pole/info/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据id删除一体杆：{}",id);
        rodManageService.delete(id);
        return Result.success();
    }

    /**
     * 新增一体杆
     * @param rodManage
     * @return
     */
    @PostMapping("/pole/info")
    public Result insert(@RequestBody RodManage rodManage){
        log.info("新增一体杆：{}",rodManage);
        rodManageService.add(rodManage);
        return Result.success();
    }

    /**
     * 更新一体杆
     * @param rodManage
     * @return
     */
    @PutMapping("/pole/info")
    public Result updata(@RequestBody RodManage rodManage){
        log.info("编辑一体杆：{}",rodManage);
        rodManageService.update(rodManage);
        return Result.success();
    }

}
